package com.car.service;

import com.car.dao.CarDao;
import com.car.dao.EmployeeDao;
import com.car.dao.impl.CarDaoImpl;
import com.car.dao.impl.EmployeeDaoImpl;
import com.car.domain.Car;
import com.car.domain.Employee;
import com.car.utils.NumberUtils;

import java.util.Scanner;

public class EmployeeService {
    private static final EmployeeDao employeeDao = new EmployeeDaoImpl();
    private static final CarDao carDao = new CarDaoImpl();
    public Employee login(Scanner scanner) throws Exception {
        System.out.println("员工登录");
        System.out.println("请输入工号");
        String worId = scanner.next();
        System.out.println("请输入密码");
        String password = scanner.next();
        Employee employee = employeeDao.findByWorkId(worId);
        if (employee == null || !"000000".equals(password)){
            System.out.println("登陆失败");
            return null;
        }
        System.out.println("员工:" + employee.getName() + ".登陆成功");
        return employee;
    }

    public void addCar(Employee employee, Scanner scanner) throws Exception {
        System.out.println("上架汽车");
        Car car = new Car();
        //给Car赋值
        System.out.println("请输入汽车名字");
        String carName = scanner.next();
        car.setName(carName);
        System.out.println("请输入汽车品牌");
        String brand = scanner.next();
        car.setBrand(brand);
        System.out.println("请输入汽车颜色");
        String color = scanner.next();
        car.setColor(color);
        System.out.println("请输入汽车类型");
        String type = scanner.next();
        car.setType(type);
        System.out.println("请输入汽车价格");
        double price = scanner.nextDouble();
        car.setPrice(price);
        car.setCarNum(NumberUtils.generateCardNum());
        car.setEmployeeId(employee.getId());
        //插入数据
        int i =carDao.add(car);
        if (i > 0){
            System.out.println("上架成功");
        }else {
            System.out.println("操作失败");
        }
    }
}
